﻿/*******************************************************************************
#                    TalentBroker.cs
#  Comment:
#
#  Current Version: V1.0
#  Author: 
#
#  History List:
#  V1.0    Created by Onions@2009-8-21 13:08:14
#
#******************************************************************************/
#region Usings
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using SYS.Basic;

using ExpertMIS.Brokers;
using ExpertMIS.Entities;
using System.Collections;
#endregion

namespace ExpertMIS.Brokers
{
    public class TalentBroker : ExpertMISBaseBroker
    {
        #region Private Methods

        private object UpdateTalentEntity(IEntity entity)
        {
            return SqlMap.Update("UpdateTalentEntity", entity);
        }

        private object InsertTalentEntity(IEntity entity)
        {
            return SqlMap.Insert("InsertTalentEntity", entity);
        }

        private object DeleteTalentEntity(IEntity entity)
        {
            return SqlMap.Delete("DeleteTalentEntity", entity);
        }

        #endregion

        #region Override Methods

        protected override IEntity ProcessGetEntity(System.Collections.Hashtable keys)
        {
            if (!keys.Contains("OID")) throw new Exception("invalid request parameters.");
            return SqlMap.QueryForObject<IEntity>("SelectTalentEntityByOID", keys["OID"] as string);
        }

        protected override bool ProcessSaveEntity(IEntity entity, Hashtable request)
        {
            if (entity.EntityState == EntityState.New)
            {
                InsertTalentEntity(entity);
                entity.EntityState = EntityState.Old;
            }
            else
            {
                UpdateTalentEntity(entity);
            }

            return true;
        }

        protected override IEntity ProcessNewEntity()
        {
            TalentEntity entity = new TalentEntity();

            // initial entity object

            return entity;
        }

        protected override bool ProcessRemoveEntity(IEntity entity, Hashtable request)
        {
            try
            {
                DeleteTalentEntity(entity);
                return true;
            }
            catch
            {
                return false;
            }
        }

        #endregion

        /// <summary>
        /// 获取所有待审核困难列表
        /// </summary>
        /// <returns></returns>
        public IList<TalentEntity> GetAllTalents()
        {
            return SqlMap.QueryForList<TalentEntity>("SelectAllTalents", null);
        }
    }
}